package ru.susu.algebra.grouprings;

import java.io.PrintStream;
import java.math.BigInteger;

import org.apache.log4j.BasicConfigurator;

import ru.susu.algebra.algorithms.ExtendedEuclidAlgorithm;
import ru.susu.algebra.field.quadratic.GeneralUnitRecursivePeriodExtractor;
import ru.susu.algebra.field.quadratic.QuadraticFieldGeneralForm;

/**
 * @author akargapolov
 * @since: 21.06.2010
 */
public class A14Periods
{
	public static void main(String[] args)
	{
		BasicConfigurator.configure();

		PrintStream out = System.out;
		QuadraticFieldGeneralForm gUnit = new QuadraticFieldGeneralForm(1, 1, 13);

		GeneralUnitRecursivePeriodExtractor periodExtractor = new GeneralUnitRecursivePeriodExtractor();
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(64), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(9), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(25), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(49), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(13), true));

		Object sol1 = new ExtendedEuclidAlgorithm().solve(BigInteger.valueOf(60), BigInteger.valueOf(96), BigInteger.valueOf(86));
		out.println(sol1);

		Object sol2 = new ExtendedEuclidAlgorithm().solve(BigInteger.valueOf(96), BigInteger.valueOf(112), BigInteger.valueOf(68));
		out.println(sol2);

		BigInteger a = BigInteger.valueOf(96);
		BigInteger b = BigInteger.valueOf(60);
		BigInteger c = BigInteger.valueOf(112);
		a = a.multiply(b).divide(a.gcd(b));
		a = a.multiply(c).divide(a.gcd(c));
		out.println(a);

		gUnit = new QuadraticFieldGeneralForm(19, 8, 33);
		periodExtractor = new GeneralUnitRecursivePeriodExtractor();
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(4), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(9), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(25), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(49), true));
		//out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(11), true));

		a = BigInteger.valueOf(30);
		b = BigInteger.valueOf(56);
		a = a.multiply(b).divide(a.gcd(b));
		out.println(a);
		sol2 = new ExtendedEuclidAlgorithm().solve(BigInteger.valueOf(15120), BigInteger.valueOf(18), BigInteger.valueOf(6));
		out.println(sol2);

		gUnit = new QuadraticFieldGeneralForm(0, 1, 5);
		periodExtractor = new GeneralUnitRecursivePeriodExtractor();
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(64), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(81), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(5), true));
		out.println(periodExtractor.performOperation(gUnit, BigInteger.valueOf(49), true));
		a = BigInteger.valueOf(96);
		b = BigInteger.valueOf(112);
		a = a.multiply(b).divide(a.gcd(b));
		out.println(a);
		a = BigInteger.valueOf(672);
		b = BigInteger.valueOf(72);
		a = a.multiply(b).divide(a.gcd(b));
		out.println(a);
		sol2 = new ExtendedEuclidAlgorithm().solve(BigInteger.valueOf(672), BigInteger.valueOf(72), BigInteger.valueOf(16));
		out.println(sol2);
	}

}
